<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.simpleforum.model.Post" %>
<%@ page import="com.example.simpleforum.model.Reply" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>个人中心 - 极简论坛</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
    <h1>个人中心</h1>
    <div class="actions">
        <a href="index.jsp" class="btn">返回首页</a>
        <a href="PostListServlet" class="btn">帖子列表</a>
    </div>
    
    <div class="user-posts">
        <h2>我的帖子</h2>
        <% 
            List<Post> posts = (List<Post>) request.getAttribute("posts");
            if (posts != null && !posts.isEmpty()) {
                for (Post post : posts) {
        %>
        <div class="post-item">
            <h3><a href="PostDetailServlet?id=<%= post.getId() %>"><%= post.getTitle() %></a></h3>
            <div class="post-meta">
                <span>发布时间: <%= post.getCreateTime() %></span>
                <% if (post.getUpdateTime().after(post.getCreateTime())) { %>
                <span>最后编辑: <%= post.getUpdateTime() %></span>
                <% } %>
            </div>
            <div class="post-actions">
                <a href="PostEditServlet?id=<%= post.getId() %>" class="btn">编辑</a>
                <a href="PostDeleteServlet?id=<%= post.getId() %>" class="btn" onclick="return confirm('确定要删除这篇帖子吗？')">删除</a>
            </div>
        </div>
        <% 
                }
            } else {
        %>
        <p>暂无帖子</p>
        <a href="PostAddServlet" class="btn">发布新帖</a>
        <% } %>
    </div>
    
    <div class="user-replies">
        <h2>我的回复</h2>
        <% 
            List<Reply> replies = (List<Reply>) request.getAttribute("replies");
            if (replies != null && !replies.isEmpty()) {
                for (Reply reply : replies) {
        %>
        <div class="reply-item">
            <div class="reply-meta">
                <span>回复时间: <%= reply.getCreateTime() %></span>
                <% if (reply.getUpdateTime().after(reply.getCreateTime())) { %>
                <span>最后编辑: <%= reply.getUpdateTime() %></span>
                <% } %>
            </div>
            <div class="reply-content">
                <%= reply.getContent() %>
            </div>
            <div class="reply-actions">
                <a href="ReplyEditServlet?id=<%= reply.getId() %>" class="btn">编辑</a>
                <a href="ReplyDeleteServlet?id=<%= reply.getId() %>" class="btn" onclick="return confirm('确定要删除这条回复吗？')">删除</a>
                <a href="PostDetailServlet?id=<%= reply.getPostId() %>" class="btn">查看帖子</a>
            </div>
        </div>
        <% 
                }
            } else {
        %>
        <p>暂无回复</p>
        <% } %>
    </div>
</div>
</body>
</html>